<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tld/struts-html" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic" prefix="logic"%>
<%@ taglib uri="/WEB-INF/tld/jstl/c" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/jstl/fn" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="">
		<title>广告管理-添加</title>
		<link rel="stylesheet" type="text/css" href="/admin/css/css.css">
		<script type='text/javascript' src='/dwr/interface/homeSiteDWRServ.js'></script>
		<script type='text/javascript' src='/dwr/engine.js'></script>
		<script type='text/javascript' src='/dwr/util.js'></script> 
		
		<script type="text/javascript">
				function checkForm()
				{
					//alert('hsDesId 值：'+document.forms[0].hsDesId.value);
					
				  var f = document.forms[0];
				  	if(document.getElementById('firstNewsClassId').value==-1)
				  	{
				     alert('请选择一个一级分类');
				     return false;
				  	}
				  
				  	if(document.getElementById('secondNewsClassId').value==-1)
				  	{
				     alert('请选择一个二级分类');
				     return false;
				  	}
				  
				  if(f.hsDesId.value==-1){
				     alert('请选择一个广告描述');
				     return false;
				  }
				   if(f.title.value==''){
				     alert('标题不能为空');
				     return false;
				  }
				  
				  var chkImg = f.chkImg;
				  if(chkImg.checked)
				  {
				  		var pic = f.pic;
				  		if(pic.value == '')
				  		{
				  			alert('选择图片广告后，图片必须上传');
				  			return false;
				  		}
				  }
				  
				 var chkJs = f.chkJs;
				  if(chkJs.checked)
				  {
					  var link = f.link.value;
					  if(link == '')
					  {
					     alert('若开启外部链接，则外部链接不能为空');
					     return false;
					  }
					  if(link.indexOf('http://') == -1)
					  {
					     alert('链接格式不对，必须以 http:// 开头');
					     return false;
					  }
				  }	
				  
				  if(f.content.value.length>50){
				  	alert('广告内容字符不能超过50……');
				  	return false;
				  }
				  if(f.js.value.length>500){
				  	alert('JS内容字符不能超过500……');
				  	return false;
				  }
				  
				  
				  var chkJs = document.getElementById('chkJs');
				  if(chkJs.checked)
				  {
					  var js = document.getElementById('js').value;
					  if(js.indexOf('<script')==-1 || js.indexOf('<\/script>')==-1)
					  {
					  		alert('JS内容必须以 <script 开头 ，以<\/script>结尾');
					  		return false;
					  }
				  
				  }
				  
				  return true;
				}
				
				function upImg()
				{
					var ischk = document.getElementById('chkImg').checked;
					if(ischk){
						document.getElementById('pic').disabled = false;
						document.getElementById('isImg').value = 1;
					}else{
						document.getElementById('pic').disabled = true;
						document.getElementById('isImg').value = 0;
					}
				}
				
				function upLink(){
					var ischk = document.getElementById('chkLink').checked;
					if(ischk){
						document.getElementById('link').disabled = false;
						document.getElementById('isLink').value = 1;
					}else{
						document.getElementById('link').disabled = true;
						document.getElementById('isLink').value = 0;
					}
				}
				
				function upJs()
				{
					var ischk = document.getElementById('chkJs').checked;
					if(ischk){
						document.getElementById('js').disabled = false;
						document.getElementById('isJs').value = 1;
					}else{
						document.getElementById('js').disabled = true;
						document.getElementById('isJs').value = 0;
					}
				}
				
		</script>
		<script type="text/javascript" language="javascript">
		  //通过一级分类id,获取二级分类的列表
		  function loadSecondHomeSiteClassList()
		  {
		      var newsClassId = document.getElementById('firstNewsClassId').value;
		     if(newsClassId!=null  && newsClassId!='-1')
		     {
		        //获取二级列表
		        homeSiteDWRServ.loadSecondHomeSiteNewsClassByAdType(newsClassId,fillSecondList);
		        
		     }
		  }
		  
		  
		  //通过二级分类id,获取三级分类的列表
		   function loadThirdHomeSiteClassList()
		  {
		      var newsClassId = document.getElementById('secondNewsClassId').value;
		     if(newsClassId!=null  && newsClassId!='-1')
		     {
		        //获取二级列表
		        homeSiteDWRServ.loadSecondHomeSiteNewsClassByAdType(newsClassId,fillThirdList);
		        
		        //通过二级分类的id,加载出广告描述列表
		        getHomeSiteAdBannerDescriptionList(newsClassId);
		     }
		  }
		     
		  //通过三级分类id,加载出广告描述列表
		  function  loadAdBannerDescriptionList()
		  {
		     var newsClassId = document.getElementById('thirdNewsClassId').value;
		     if(newsClassId!=null  && newsClassId!='-1')
		     {
		        //通过三级分类的id,加载出广告描述列表
		        getHomeSiteAdBannerDescriptionList(newsClassId);
		     }
		  }
		  
		  //通过分类id,获取广告描述列表
		  var newsClassId;
		  function getHomeSiteAdBannerDescriptionList(newsClassId)
		  {
		      homeSiteDWRServ.loadAdBannerListByHomeSiteNewsClassId(newsClassId,fillDescription);
		  }
		  
		  var data;
		  function fillDescription(data)
		  {
		    DWRUtil.removeAllOptions("hsDesId");
            //DWRUtil.addOptions("hsDesId", data.id,data.picName);
            DWRUtil.addOptions("hsDesId", {'-1':'请选择'});
            DWRUtil.addOptions("hsDesId", data);
		  }
		  
		  //二级分类列表
		  var data2;
		  function fillSecondList(data2)
		  {
		    DWRUtil.removeAllOptions("secondNewsClassId");
            //DWRUtil.addOptions("secondNewsClassId", data2.id,data2.picName);
            DWRUtil.addOptions("secondNewsClassId", {'-1':'请选择'});
            DWRUtil.addOptions("secondNewsClassId", data2);
		  }
		  
		  
		  //填充三级分类列表
		  var data3;
		  function fillThirdList(data3)
		  {
		    DWRUtil.removeAllOptions("thirdNewsClassId");
            //DWRUtil.addOptions("thirdNewsClassId", data3.id,data3.picName);
            DWRUtil.addOptions("thirdNewsClassId", {'-1':'请选择'});
            DWRUtil.addOptions("thirdNewsClassId", data3);
		  }
		  
		</script>
		<style type="text/css">
			<!--
			.STYLE1 {font-size: 12px}
			-->
		</style>
	</head>
	<body>
		
	  <html:form action="/admin/banner/homeSiteAdBanner.do?action=add" method="post" enctype="multipart/form-data" onsubmit="return checkForm();">
			
			<html:hidden property="isImg" value="1"/>
			<html:hidden property="isLink" value="1"/>
			<html:hidden property="isJs" value="1"/>
			
				<table width="100%" height="201" border="0" cellpadding="3"
					cellspacing="1">
					<tr>
						<td width="10%" bgcolor="#FEDFC0" class="STYLE1">
							分 类：
						</td>
						<td width="20%" bgcolor="#F6F6F6">
							<span class="STYLE1">一级分类</span>
							<html:select property="firstNewsClassId" onchange="loadSecondHomeSiteClassList();">
							   <html:option value="-1">---请选择---</html:option>
							   <html:optionsCollection name="firstHomeSiteNewsClassList" label="names" value="id"/>
							</html:select>
							<font color="red">*</font>
						</td>
						<td width="20%" bgcolor="#F6F6F6">
							<span class="STYLE1">二级分类</span>
							<html:select property="secondNewsClassId" onchange="loadThirdHomeSiteClassList();">
							   <html:option value="-1">---请选择---</html:option>
							</html:select>
							<font color="red">*</font>
						</td>
						<td width="20%" bgcolor="#F6F6F6">
							<span class="STYLE1">三级分类</span>
							<html:select property="thirdNewsClassId" onchange="loadAdBannerDescriptionList();">
							   <html:option value="-1">---请选择---</html:option>
							</html:select>
							<font color="red">*</font>
						</td>
						
					</tr>
					
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							广告描述：
						</td>
						<td bgcolor="#F6F6F6" colspan="3">
							<span class="STYLE1">选择图片描述</span>
							<select name="hsDesId" id="hsDesId">
								<option value="-1">---请选择---</option>
							</select>
							<font color="red">*</font>
						</td>
					</tr>
					
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							标 题：
						</td>
						<td width="15%" bgcolor="#F6F6F6">
							<html:text property="title" value=""
								size="20" maxlength="100"></html:text>
								<font color="red">*</font>			
						</td>
																	
						<td bgcolor="#F6F6F6" colspan="3">
								<input id="chkImg" type="checkbox"  onclick="upImg();" checked="checked"/>
							<span class="STYLE1">是否图片新闻</span>
							&nbsp;&nbsp;							
							<input id="chkLink" type="checkbox" onclick="upLink();" checked="checked"/>
							
							<span class="STYLE1">是否启用外部链接</span>
							&nbsp;&nbsp;
									<input id="chkJs" name="chkJs" type="checkbox" onclick="upJs();"/>
							<span class="STYLE1">开启js广告</span>

						</td>
					</tr>
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							内容：
						</td>
						<td colspan="5" bgcolor="#F6F6F6">
							<textarea name="content" cols="50" rows="5"></textarea>
							<font color="red">注：广告内容字符不能超过100字</font>			
						</td>
					</tr>
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							<p>
								图片上传：
							</p>
						</td>
						<td colspan="5" bgcolor="#F6F6F6">
							<input type="file" name="pic" value="">
							<logic:present name="error">
								<b><font color="red">
									<bean:write name="error"/>
								</font></b>
							</logic:present>
						</td>
					</tr>
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							外部链接：
						</td>
						<td colspan="5" bgcolor="#F6F6F6">
							<label><input name="link" value="" maxlength="100"/></label>&nbsp;
							<font color="red">*&nbsp;注意：格式必须是 http:// 开头</font>			
						</td>
					</tr>
					<tr>
						<td bgcolor="#FEDFC0" class="STYLE1">
							JS广告：
						</td>
						<td colspan="5" bgcolor="#F6F6F6">
									<label>
										<textarea name="js" rows="10" cols="50" disabled="disabled"></textarea>
										<font color="red">注：JS内容字符不能超过500字</font>										
									</label>
						</td>
					</tr>
					<tr>
					<td colspan="4">
						<font color="red">注意：广告添加：先选择各级分类、再选择描述、最后填写必要信息</font>
					</td>
					</tr>
				</table>
				<p>
					<input type="submit" value="确定添加">
					&nbsp;
					<input type="reset" value="重置">
					&nbsp;
				</p>

		</html:form>
		<logic:present name="msg">
			<bean:write name="msg" filter="false"/>
		</logic:present>
		
	</body>
</html>
